import request from "@/utils/request";

/**@baseSaleAttrItemType  基础销售属性的某一个类型*/
export interface baseSaleAttrItemType {
  id?: number;
  name: string;
}

/**@baseSaleAttrListType 基础销售属性列表的类型*/
export type baseSaleAttrListType = baseSaleAttrItemType[];

/**@spuImageItemType spu图片列表某一项类型 */
export interface spuImageItemType {
  id?: number;
  imgName: string;
  imgUrl: string;
  spuId?: number;
  name?: string;
  url?: string;
  response?: any;
  isDefault?: string;
}

/**@spuImageListType spu图片列表的类型 */
export type spuImageListType = spuImageItemType[];

/**@spuSaleAttrValueItemType spu销售属性值的列表中某一项的类型 */
export interface spuSaleAttrValueItemType {
  baseSaleAttrId?: number;
  id?: number;
  isChecked?: string;
  saleAttrName?: string;
  saleAttrValueName: string;
  spuId?: number;

}

/**@spuSaleAttrValueListType spu销售属性值列表的数据类型 */
export type spuSaleAttrValueListType = spuSaleAttrValueItemType[];

/**@spuSaleAttrItemType 某个spu销售属性列表中某一项的类型*/
export interface spuSaleAttrItemType {
  baseSaleAttrId?: number;
  id?: number;
  saleAttrName: string;
  spuId?: number;
  spuSaleAttrValueList: spuSaleAttrValueListType;
  isEdit?: boolean;
  inputValue?: string;
  attrIdAttrValueId?: string;
}

/**@spuSaleAttrListType spu销售属性列表类型*/
export type spuSaleAttrListType = spuSaleAttrItemType[];

/**@SpuInfoType 完整的spu信息的类型*/
export interface spuInfoType {
  category3Id: number | null;
  description: string;
  id?: number;
  spuName: string;
  tmId?: number | null;
  spuImageList: spuImageListType | null;
  spuSaleAttrList: spuSaleAttrListType | null;
}

/**@spuListType spu分页列表数据类型*/
export interface spuListType {
  total: number;
  size: number;
  current: number;
  searchCount: boolean;
  pages: number;
  records: spuInfoType[];
}

//1.所有销售属性的请求
/**@requestBaseSaleAttrList 请求spu的所有销售属性列表*/
export const requestBaseSaleAttrList = () => {
  return request.get<any, baseSaleAttrListType>(
    `/admin/product/baseSaleAttrList`
  );
};
//2.删除spu的请求
/**@requestDeleteSpu 根须spuId删除Spu*/
export const requestDeleteSpu = (spuId: number) => {
  return request.delete<any, null>(`/admin/product/deleteSpu/${spuId}`);
};

//3.新添spu的请求
/**@requestSaveSpuInfo 新增spu*/
export const requestSaveSpuInfo = (spuInfo: spuInfoType) => {
  return request.post(`/admin/product/saveSpuInfo`, spuInfo);
};

//4.更新spu的请求
/**@requestUpdateSpuInfo 更新Spu*/
export const requestUpdateSpuInfo = (spuInfo: spuInfoType) => {
  return request.post(`/admin/product/updateSpuInfo`, spuInfo);
};

//5.spu的分裂列表的请求
/**@requestSpuList 获取spu的分页列表*/
export const requestSpuList = (
  page: number,
  limit: number,
  category3Id: number
) => {
  return request.get<any, spuListType>(
    `/admin/product/${page}/${limit}?category3Id=${category3Id}`
  );
};

//6.spu图片列表的请求
/**@requestSpuImgList 根据spuId获取Spu图片列表*/
export const requestSpuImgList = (spuId: number) => {
  return request.get<any, spuImageListType>(`/admin/product/spuImageList/${spuId}`);
};

//7.当前销售属性的请求
/**@requestSpuSaleAttrList 根据spuId获取当前的销售属性*/
export const requestSpuSaleAttrList = (spuId: number) => {
  return request.get<any, spuSaleAttrListType>(`/admin/product/spuSaleAttrList/${spuId}`);
};
